<template>
	<view class="content">
		<view class="search-box">
			<view class="input-box">
				<input type="text" :placeholder="defaultKeyword" @input="inputChange" v-model="keyword" @confirm="doSearch()"
				 placeholder-class="placeholder-class" confirm-type="search">
			</view>
			<view class="search-btn" @tap="doSearch()">确定</view> 
		</view>
		<view class="goods-list">
			<view v-for="(item, index) in vehicleBoxGoodsVos" :key="index" class="goods-item" >
				<!-- 正常,柜门关闭的情况 -->
				<view  v-if="item.boxStatus == '0'" class='BoxItem1'>
					<text class="box-index">{{item.boxIndex}}号柜:</text>
					<text class="box-product-title">{{item.productName}}</text>
					<view class="box-info">
						<view class="">
							<text style="font-size: 36rpx;" class="price">价格:{{item.price}}</text>
							<text class="text-gray text-df" style="font-size: 24rpx;">剩余数量:{{item.count}}</text>
						</view>
					</view>
					<view class="box-button">
						<view class="">
							<button class="open btn" style="background-color: #4CAF50;" @tap="openIndex(item.boxIndex)">打开柜门</button>
								<button class="out btn" style="background-color: #999999;" @tap="vehicleBoxDownGoods(item.boxIndex)">下架商品</button>
								<button class="added btn" style="background-color: #c89ef2;" @tap="vehicleBoxUpGoods(item.boxIndex)">上架商品</button>
							
						</view>
					</view>
				</view>
				<!-- 处理关闭状态的柜子 -->
				<view v-else-if="item.boxStatus == '-1'" class="BoxItem">
					<view class="box-left">
						<text>{{item.boxIndex}}</text>
					</view>
					<view class="box-right">
						<text class="box-right-title">{{item.productName}}商品名称</text>
						<view class="box-info">
							<text class="price">价格：￥{{item.price}}</text>
							<text class="box-info-count">剩余数量：{{item.count}}</text>
						</view>
						<view class="box-button">
							<button class="open btn" style="background-color: #4CAF50;" @tap="openIndex(item.boxIndex)">打开柜门</button>
							<button class="out btn" style="background-color: #999999;" @tap="vehicleBoxDownGoods(item.boxIndex)">下架商品</button>
							<button class="added btn" style="background-color: #c89ef2;" @tap="vehicleBoxUpGoods(item.boxIndex)">上架商品</button>
						</view>
					</view>
				</view>
				<!-- 处理红色,即柜门打开的情况 -->
				<view v-else  class="BoxItem2">
					<text class="box-index">{{item.boxIndex}}号柜:</text>
					<text class="box-product-title">{{item.productName}}</text>
					<view class="box-info">
						<view class="">
							<text style="font-size: 36rpx;" class="price">价格:{{item.price}}</text>
							<text class="text-gray text-df" style="font-size: 24rpx;">剩余数量:{{item.count}}</text>
						</view>
					</view>
					<view class="box-button">
						<button class="open btn" style="background-color: #4CAF50;" @tap="openIndex(item.boxIndex)">打开柜门</button>
						<button class="out btn" style="background-color: #999999;" @tap="vehicleBoxDownGoods(item.boxIndex)">下架商品</button>
						<button class="added btn" style="background-color: #c89ef2;" @tap="vehicleBoxUpGoods(item.boxIndex)">上架商品</button>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	//引用mSearch组件，如不需要删除即可
	// import mSearch from '@/components/mehaotian-search-revision.vue';
	export default {
		data() {
			return {
				defaultKeyword: "输入车辆vehicleNo",
				keyword: "",
				oldKeywordList: [],
				hotKeywordList: [],
				keywordList: [],
				forbid: '',
				isShowKeywordList: false,
				oldUrl: 'https://app.mosunshine.com/prod-api/',
				newUrl: 'https://mall.mosunshine.com/',
				vehicleBoxGoodsVos: [],
				allCarGoods: [],
				nowCarNo: '',
				clickNo: -1,
			}
		},
		onLoad() {
			this.init();
		},
		components: {
			//引用mSearch组件，如不需要删除即可
		},
		methods: {
			init() {

			},
			// 打开柜子
			openIndex(boxIndex) {
				const that = this
				uni.request({
					method:'GET',
				    url: that.newUrl +'vehicle/web/openVehicleBox',
					header: {
						'Authorization': 'Bearer '+ uni.getStorageSync('token'),
						'content-type': 'application/json',
					},
				    data: {
						vehicleNo:  that.nowCarNo,
						boxIndex: boxIndex
					},
				    success: (res) => {
						console.log('res')
						console.log(res)
				    }
				});
			},
			// 商品下架
			vehicleBoxDownGoods(boxIndex) {

			},
			// 商品上架
			vehicleBoxUpGoods(boxIndex) {

			},
			//执行搜索
			doSearch() {
				const that = this
				that.nowCarNo = that.keyword
				uni.request({
					method:'GET',
				    url: that.newUrl +'vehicle/app/getVehicleBoxGoodsInfo',
					header: {
						'Authorization': 'Bearer '+ uni.getStorageSync('token'),
						'content-type': 'application/x-www-form-urlencoded',
					},
				    data: {
						vehicleNo:  that.nowCarNo
					},
				    success: (res) => {
						that.vehicleBoxGoodsVos = res.data.data.vehicleBoxGoodsVos
				    }
				});
				uni.request({
					method:'GET',
				    url: that.newUrl +'vehicle/web/getVehicleInGoods',
					header: {
						'Authorization': 'Bearer '+ uni.getStorageSync('token'),
						'content-type': 'application/x-www-form-urlencoded',
					},
				    data: {
						vehicleNo:  that.nowCarNo
					},
				    success: (res) => {
						that.allCarGoods = res.data.data
				    }
				});
			},
		}
	}
</script>
<style>
	view{display:block;}
	.goods-list {width:100%;}
	.goods-list .goods-item{width:100%;}
	.goods-list .box-index{width:100%;font-size: 28upx;color: #333;}
	.search-box {width:100%;background-color:rgb(242,242,242);padding:15upx 2.5%;display:flex;justify-content:space-between;}
	.search-box .mSearch-input-box{width: 100%;}
	.search-box .input-box {width:85%;flex-shrink:1;display:flex;justify-content:center;align-items:center;}
	.search-box .search-btn {width:15%;margin:0 0 0 2%;display:flex;justify-content:center;align-items:center;flex-shrink:0;font-size:28upx;color:#fff;background:linear-gradient(to right,#ff9801,#ff570a);border-radius:60upx;}
	.search-box .input-box>input {width:100%;height:60upx;font-size:32upx;border:0;border-radius:60upx;-webkit-appearance:none;-moz-appearance:none;appearance:none;padding:0 3%;margin:0;background-color:#ffffff;}
	.placeholder-class {color:#9e9e9e;}
	.search-keyword {width:100%;background-color:rgb(242,242,242);}
	.keyword-list-box {height:calc(100vh - 110upx);padding-top:10upx;border-radius:20upx 20upx 0 0;background-color:#fff;}
	.keyword-entry-tap {background-color:#eee;}
	.keyword-entry {width:94%;height:80upx;margin:0 3%;font-size:30upx;color:#333;display:flex;justify-content:space-between;align-items:center;border-bottom:solid 1upx #e7e7e7;}
	.keyword-entry image {width:60upx;height:60upx;}
	.keyword-entry .keyword-text,.keyword-entry .keyword-img {height:80upx;display:flex;align-items:center;}
	.keyword-entry .keyword-text {width:90%;}
	.keyword-entry .keyword-img {width:10%;justify-content:center;}
	.keyword-box {height:calc(100vh - 110upx);border-radius:20upx 20upx 0 0;background-color:#fff;}
	.keyword-box .keyword-block {padding:10upx 0;}
	.keyword-box .keyword-block .keyword-list-header {width:94%;padding:10upx 3%;font-size:27upx;color:#333;display:flex;justify-content:space-between;}
	.keyword-box .keyword-block .keyword-list-header image {width:40upx;height:40upx;}
	.keyword-box .keyword-block .keyword {width:94%;padding:3px 3%;display:flex;flex-flow:wrap;justify-content:flex-start;}
	.keyword-box .keyword-block .hide-hot-tis {display:flex;justify-content:center;font-size:28upx;color:#6b6b6b;}
	.keyword-box .keyword-block .keyword>view {display:flex;justify-content:center;align-items:center;border-radius:60upx;padding:0 20upx;margin:10upx 20upx 10upx 0;height:60upx;font-size:28upx;background-color:rgb(242,242,242);color:#6b6b6b;}
		
	.BoxItem{
		margin-top: 10px;
		background-color: #E8E6E5;
		padding: 0 10px;
		display: flex;
		align-items: center;
	}
	.BoxItem1{
		margin-top: 10px;
		background-color: #4CAF50;
		padding: 0 10px;
		display: flex;
		align-items: center;
	}
	.BoxItem2{
		margin-top: 10px;
		background-color: red;
		padding: 0 10px;
		display: flex;
		align-items: center;
	}
	.box-left{
		width: 60px;
		height: 60px;
		text-align: center;
		line-height: 60px;
		font-size: 30px;
		background-color: #ccc;
		font-weight: bold;
	}
	.box-right {
		flex: 1;
		margin: 10px;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}
	.box-info {
		font-size: 15px;
		margin: 10px 0;
	}
	.box-info-count{
		margin-left: 10px;
	}
	.box-button{
		display: flex;
	}
	.btn {
		border: none;
		border-radius: 20px;
		font-size: 15px;
	}
	.btn::after {
		border: none
	} 
</style>
